package sjtu.ist.warehouse4ws.action;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import sjtu.ist.warehouse4ws.model.Department;
import sjtu.ist.warehouse4ws.model.Epcunits;
import sjtu.ist.warehouse4ws.service.DepartmentService;
import sjtu.ist.warehouse4ws.service.FileInfoService;
import sjtu.ist.warehouse4ws.service.PrivilegeService;
import sjtu.ist.warehouse4ws.vo.FullSearchVO;

import com.googlecode.jsonplugin.annotations.JSON;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;

public class ShowSearchAction extends ActionSupport{
	private FileInfoService fileInfoService;
	private PrivilegeService privilegeService;
//	private List<Fileinfo> fileList = new ArrayList<Fileinfo>();
	private List<FullSearchVO> fileList = new ArrayList<FullSearchVO>();
	
	//departmentList用来转换fileinfo的department信息
	private List <Department> departmentList=new ArrayList<Department> ();
	private DepartmentService departmentService;

	private String keyWord;
	//获得Search结果列表
	public String showSearchFileList(){
		//this.fileList = fileInfoService.getAllFullSearchResult(keyWord);
		
		List<FullSearchVO> templist= fileInfoService.getAllFullSearchResult(keyWord);
		this.fileList = new ArrayList<FullSearchVO>();
		
		ActionContext actionContext=ActionContext.getContext();
		Map session=actionContext.getSession();		
		int userType=(Integer)(session.get("user_type"));
		String userCompany=session.get("user_company").toString();		
		
		for(FullSearchVO fs : templist){
			if(privilegeService.checkPrivilege(fs.getId(),userCompany,userType, "read")){
				fileList.add(fs);
			}
		}
		
		return SUCCESS;
	}
	
	//具体显示哪些内容有待修改~JSON再问问！
	@JSON(name = "totalFile")
	public int getTotalFile() {
		return this.fileList.size();
	}

	@JSON(name = "File")
	public List<FullSearchVO> getFileList() {
		return this.fileList;
	}
	
	public void setFileList(List<FullSearchVO> fileList) {
		this.fileList = fileList;
	}
	
	// 注入FileInfoService
	public void setFileInfoService(FileInfoService fileInfoService) {
		this.fileInfoService = fileInfoService;
	}

	public void setPrivilegeService(PrivilegeService privilegeService) {
		this.privilegeService = privilegeService;
	}

	public String getKeyWord() {
		return keyWord;
	}

	public void setKeyWord(String keyWord) {
		this.keyWord = keyWord;
	}
}